/*
 * IkaWindows.cpp
 */

#include "IkaWindows.h"

namespace atomic {

IkaWindows::IkaWindows() :
	sf::RenderWindow() {
}

IkaWindows::~IkaWindows() {
}

void IkaWindows::MainLoop() {
	while(myApp->IsOpened()){
			Update(); // TODO : compteurs differentiés
			Render();
		}
		printf("Well Done\n");
}

IkaWindows::IkaWindows(const IkaWindow & copy) {
}

void IkaWindows::Delete() {
	delete myApp;
	delete mySprite;
	delete myImage;
	delete Bob;
	delete Barbara;
	delete Bill;
}

void IkaWindows::Init() {
	SetSize(200,150);
	// ***********************
	myImage = new sf::Image();
	mySprite = new sf::Sprite();

	if (!myImage->LoadFromFile("img/mojo.png")) {
		printf("OUPS");
	}
	mySprite->SetImage(*myImage);
	// ***********************
	Bob = new IkaGraphic();
	Bob->LoadFile("img/duke.png");
	Bob->Sprite().SetX(50);
	// ***********************
	Barbara = new IkaAnim();
	Barbara->AddFrame("frame1");
	Barbara->AddFrame("frame2");
	Barbara->AddFrame("map");
	Barbara->AddFrame("frame4");
	Barbara->AddFrame("frame1");
	Barbara->AddFrame("frame2");
	Barbara->AddFrame("map");
	Barbara->AddFrame("frame4");
	Barbara->AddFrame("frame1");
	Barbara->GetFrame(2)->Sprite().SetY(50); //TODO + propre + utiliser render() & update()
	// ************************
	Bill = new IkaCore();
	Bill->SetAnim(Barbara, 0);
	Bill->AddAnim("frame"); //TODO trouble
}

void IkaWindows::Update(){
	// process events
		sf::Event event;
		while (myApp->GetEvent(event)) {
			if (event.Type == sf::Event::Closed)
				myApp->Close();

			if ((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Key::Escape))
				myApp->Close();
		}
}

void IkaWindows::Render(){
	myApp->Clear(sf::Color(255,255,255));

		/*
		 int size = myElements.size();
		 int i = 0;
		 printf("size: %d \n", i);
		 while(i < size){
		 myApp.Draw(myElements.at(i).Graphic().Sprite());
		 i++;
		 }
		 */

		myApp->Draw(*mySprite);
		myApp->Draw(Bob->Sprite());
		myApp->Draw(Barbara->GetFrame(2)->Sprite());
		myApp->Display();
}

//*********************************************************************
void IkaClient::Add(const IkaCore & core) {
	//myElements.push_back(core);
}


}
